import 'dart:convert';
import 'package:cloud_medicine/components/util.dart';
import 'package:cloud_medicine/http/HttpUtil.dart';
import 'package:cloud_medicine/http/config.dart';
import 'package:dio/dio.dart';

// 获取聊天
Future getChatList_api(String url) async {
  String token = await getToken();
  Response res = await HttpUtil.request(
    url,
    method: HttpUtil.GET,
    headers: {'Authorization': token},
  );
  return jsonDecode(res.data);
}

// 搜索聊天
Future searchChat_api(String url, dynamic data) async {
  String token = await getToken();
  Response res = await HttpUtil.get(
    url,
    parameters: data,
    headers: {'Authorization': token},
  );
  return jsonDecode(res.data);
}

// 获取聊天具体信息
Future getChatDetail_api(Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.get(
    '$backIP/chat/chatDetail',
    parameters: data,
    headers: {'Authorization': token},
  );
  return jsonDecode(res.data);
}

// 增加聊天
Future addChat_api(Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.request(
    '$backIP/chat/sendMessage',
    parameters: data,
    method: HttpUtil.POST,
    headers: {'Authorization': token},
  );
  return jsonDecode(res.data);
}

// 移除聊天
Future removeChat_api(Map<String, dynamic> data) async {
  String token = await getToken();
  Response res = await HttpUtil.request(
    '$backIP/chat',
    parameters: data,
    method: HttpUtil.DELETE,
    headers: {'Authorization': token},
  );
  return jsonDecode(res.data);
}